<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!--#include file="../inc/conn.asp"-->
<!--#include file="../inc/md5.asp"-->
<!--#include file="../common/admin.asp"-->
<%
key=request.QueryString("key")
mark=request.QueryString("mark")
pay=request.QueryString("pay")
search=request.QueryString("search")
if search="搜索" then
	  if key<>"" then
			sqlsearch=" and (orderid like '%"&key&"%')"
	  end if
	  if pay<>"" then
			sqlsearch=sqlsearch+" and faremark="&pay&""
	  end if
	  if mark<>"" then
			sqlsearch=sqlsearch+" and mark="&mark&""
	  end if
end if
'分页-------------------------------------------------------
set Rs=server.CreateObject("ADODB.RecordSet")
sql="select count(sortid) from (Select ROW_NUMBER() OVER (order by id desc ) as sortid,* From Orderdaipai) as TempTable where 1=1 "&sqlsearch&""
Pager_Pagesize=10 '每页记录数
Rs.open sql,conn,1,1
Pager_TotalRecord=Rs(0) '总记录数
Rs.close
Pager_PageCount=int((Pager_TotalRecord/Pager_Pagesize)+0.99999) '计算总页数
CurrentPage=Request("page") '当前页
'如果不为数字则直接设置页码为1
if isnumeric(CurrentPage)=False Or CurrentPage="" then
	CurrentPage=1
'如果当前页数大于总页数，则直接设置页码为1
elseif  Clng(CurrentPage)>Pager_PageCount then
	CurrentPage=1
end if
Fieldsname=" id,orderid,uid,faremark,Proquantity,Proprice,Fareprice,Mark,Addtime,sortid"
orderBy=" Order by sortid asc"
'拆分SQL语句，必须是select开头，有唯一标识的列
if instr("select",sql)<>-1 then
	if CurrentPage = 1 then
		sql = replace(sql,"select count(sortid)"," select  top " & Pager_Pagesize  & Fieldsname)
	else  
		sql = replace(sql,"select count(sortid)"," select  top " & Pager_Pagesize   & Fieldsname) & " and sortid >(select max(sortid) from (" & replace(sql,"select count(sortid)"," select  top " & Pager_Pagesize * (CurrentPage - 1)  & Fieldsname) & orderBy & ") AA)"
	end if
end if
sql = sql & orderBy
Rs.open sql,conn,1,1
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>main</title>
<link href="../css/style.css" rel="stylesheet" type="text/css"/>
<style>body {background-color: #eaece1;}</style>
</head>

<body>
<div class="main">
  <div class="main-title">查看</div>
  <div class="main-content">
  <table width="100%" border="0" cellspacing="1" cellpadding="3" class="tab">
  <tr>
    <td colspan="6" align="center">
    <form name="form" method="get" action="">
    <input name="key" type="text" id="key" value="<%=key%>" maxlength="50" />
    <select name="pay" id="pay">
      <option value="">运费支付状态</option>
      <option value="0" <%if mark="0" then response.Write " selected"%>>未支付</option>
      <option value="1" <%if mark="1" then response.Write " selected"%>>已支付</option>
    </select>
    <select name="mark" id="mark">
      <option value="">订单状态</option>
      <option value="1" <%if mark="1" then response.Write " selected"%>>未处理</option>
      <option value="2" <%if mark="2" then response.Write " selected"%>>等待投标</option>
      <option value="3" <%if mark="3" then response.Write " selected"%>>已中标</option>
      <option value="4" <%if mark="4" then response.Write " selected"%>>已发货</option>
      <option value="0" <%if mark="0" then response.Write " selected"%>>已取消</option>
      <option value="6" <%if mark="6" then response.Write " selected"%>>已完成</option>
    </select>
    <input type="submit" name="search" value="搜索" />
    </form>
    </td>
    </tr>
    </table>
  <table width="100%" border="0" cellspacing="1" cellpadding="3" class="tab">
  <form action="" method="post">
  <tr>
    <td align="center" bgcolor="#FFFFFF"><strong>选择</strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong><span class="items">订单号</span></strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong><span class="items">会员</span></strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong><span class="items">运费支付状态</span></strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>总金额</strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>货物金额</strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>运费</strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>状态</strong></td>
    <td align="center" bgcolor="#FFFFFF"><strong>操作</strong></td>
    <td bgcolor="#FFFFFF"><strong>添加时间</strong></td>
    </tr>
    <%do while not Rs.eof%>
  <tr>
    <td align="center" bgcolor="#FFFFFF"><input type="checkbox" name="checkbox" id="checkbox" value="<%=rs("orderid")%>" <%if rs("mark")=6 or rs("mark")=0 then response.Write " disabled "%>/>
      <input name="money<%=rs("orderid")%>" type="hidden" value="<%=formatNumber(cdbl(rs("Proprice"))*cdbl(rs("Proquantity"))+cdbl(rs("Fareprice")),2)%>" />
      <input name="user<%=rs("orderid")%>" type="hidden" value="<%=rs("uid")%>" /></td>
    <td align="center" bgcolor="#FFFFFF"><%=rs("orderid")%></td>
    <td align="center" bgcolor="#FFFFFF"><%set rss=conn.execute("select mail from [user] where id="&rs("uid"))
		                               if not rss.eof then
		                               response.write rss("mail")
									   end if
									   set rss=nothing%></td>
    <td align="center" bgcolor="#FFFFFF"><%if rs("faremark")=1 then response.Write "已支付" else response.Write "未支付"%></td>
    <td align="center" bgcolor="#FFFFFF"><%=formatNumber(cdbl(rs("Proprice"))*cdbl(rs("Proquantity"))+cdbl(rs("Fareprice")),2)%></td>
    <td align="center" bgcolor="#FFFFFF"><%=cdbl(rs("Proprice"))*cdbl(rs("Proquantity"))%></td>
    <td align="center" bgcolor="#FFFFFF"><%=rs("Fareprice")%></td>
    <td align="center" bgcolor="#FFFFFF"><% 
	if rs("mark")=1 then response.Write "<font color=red>未处理</font>" 
	if rs("mark")=2 then response.Write "<font color='#0000F0'>等待投标</font>"
	if rs("mark")=3 then response.Write "<font color='#FF15FF'>已中标</font>"
	if rs("mark")=4 then response.Write "<font color='#C40FFF'>已发货</font>"
	if rs("mark")=0 then response.Write "<font color='#dddddd'>已取消</font>"
	if rs("mark")=6 then response.Write "<font color='#dddddd'>已完成</font>"
	%></td>
    <td align="center" bgcolor="#FFFFFF"><a href="daipaiadd.asp?id=<%=rs("orderid")%>">查看</a></td>
    <td bgcolor="#FFFFFF"><%=rs("addtime")%></td>
    </tr>
    <%
	Rs.movenext
	loop
	Rs.close
	Set Rs=nothing
	%>
    <tr>
      <td colspan="10" align="center" bgcolor="#FFFFFF" class="page">
<input type="submit" name="button" id="button" value="删除" />
      <input type="submit" name="button" id="button" value="等待投标">  
            <input type="submit" name="button" id="button" value="已中标">
            <input type="submit" name="button" id="button" value="已发货">
            <input type="submit" name="button" id="button" value="已取消">
            <input type="submit" name="button" id="button" value="已完成">
      
      </td>
    </tr>
    </form>
    <tr>
    <td colspan="10" align="center" bgcolor="#FFFFFF" class="page">　
      <%
	siteurl=request.servervariables("document_name")
	%>
    <form action="<%=siteurl%>" method="get">
    共 <%=Pager_TotalRecord%> 条 第<%=CurrentPage%>页 / 共 <%=Pager_PageCount%> 页
		<%
		pageurl="key="&key&"&pay="&pay&"&mark="&mark&"&search="&search&"&"
		if CurrentPage=1 then
			response.Write(" 首页 ")
			response.Write(" 上一页 ")
		else
			response.Write(" <a href='"&siteurl&"?"&pageurl&"page=1'>首页</a> ")
			response.Write(" <a href='"&siteurl&"?"&pageurl&"page="& (CurrentPage-1) &"'>上一页</a> ")
		end if
		%>
		<%
		if Clng(CurrentPage)=Clng(Pager_PageCount) then
			response.Write(" 下一页 ")
			response.Write(" 尾页 ")
		else
			response.Write(" <a href='"&siteurl&"?"&pageurl&"page="& (CurrentPage+1) &"'>下一页</a> ")
			response.Write(" <a href='"&siteurl&"?"&pageurl&"page="& Pager_PageCount &"'>尾页</a> ")
		end if
		%>
		&nbsp;
		<input name="page" type="text" value="<%=CurrentPage%>" size="1" maxlength="10" />
        <input type="submit" name="button" value="跳转" />
        <input type="hidden" name="key" value="<%=key%>" />
        <input type="hidden" name="mark" value="<%=mark%>" />
        <input type="hidden" name="pay" value="<%=pay%>" />
        <input type="hidden" name="search" value="搜索" />
        </form>
      </td>
    </tr>
  </table>
</div>
</div>
</body>
</html>
<%
checkbox=request.Form("checkbox")
if checkbox<>"" then	
	if request.Form("button")="删除" then
	    moneyuser=split(replace(checkbox," ",""),",")
        for f=0 to ubound(moneyuser)
		   conn.execute("update [user] set money=money+"&cdbl(request.Form("money"&moneyuser(f)))&" where id = "&request.Form("user"&moneyuser(f))&"")
		next
		conn.execute("delete from Orderdaipai where orderid in("&checkbox&")")

	elseif request.Form("button")="等待投标" then
		conn.execute("update Orderdaipai set mark=2 where orderid in ("&checkbox&")")
		
	elseif request.Form("button")="已中标" then
		conn.execute("update Orderdaipai set mark=3 where orderid in ("&checkbox&")")
	
	elseif request.Form("button")="已发货" then
		conn.execute("update Orderdaipai set mark=4 where orderid in ("&checkbox&")")
		
	elseif request.Form("button")="已取消" then
	    moneyuser=split(replace(checkbox," ",""),",")
        for f=0 to ubound(moneyuser)
		   conn.execute("update [user] set money=money+"&cdbl(request.Form("money"&moneyuser(f)))&" where id = "&request.Form("user"&moneyuser(f))&"")
		next
		conn.execute("update Orderdaipai set mark=0 where orderid in ("&checkbox&")")
	
	elseif request.Form("button")="已完成" then
		conn.execute("update Orderdaipai set mark=6 where orderid in ("&checkbox&")")
	end if
	response.Redirect "daipai.asp?page="&request.QueryString("page")&""
end if
%>